package com.doitedu.day06

/**
 * @Date: 22.6.26 
 * @Author: HANGGE
 * @qq: 598196583
 * @Tips: 学大数据 ,到多易教育
 * @Description:
 */
class User(val id: Int, val name: String, val age: Int) extends  Ordered [User]{
  override def toString = s"User($id, $name, $age)"

  override def compare(that: User): Int = {
    this.age - that.age
  }
}

object User {
  // 将属性组装成对象
  def apply(id: Int, name: String, age: Int): User = new User(id, name, age)
  // 将一个对象   解构成元组
  def unapply(user: User): Option[(Int, String, Int)] = {
    if (user ==null){
      None
    }else{
      Some(user.id ,user.name,user.age)
    }
  }
}
